<template>
    <div class="fxgk-container">
      <div class="search_time">
        <van-dropdown-menu>
          <van-dropdown-item v-model="year" :options="option1" />
        </van-dropdown-menu>
      </div>
      <div class="fxgk_list">
        <div class="fxgk_one" v-for="(item,index) in dataList" :key="index">
          <div class="fxgk_one_title">
              <div class="title">
                {{item.insuranceName}}
              </div>
            <div class="type" :style="{background: (item.yearEvaluate == '优秀'?'#007AFF':(item.yearEvaluate == '良好'? '#FF9700':'#F56A00')) }">
              {{item.yearEvaluate}}
            </div>
          </div>
          <div class="fxgk_one_content">
            <div class="fxgk_content_one">
                <div class="content_num_unit">
                  <div class="content_num">
                      {{item.premium}}
                  </div>
                </div>
                  <div class="content_desc">
                    保费(￥/元)
                  </div>
            </div>
            <div class="fxgk_content_one">
                <div class="content_num_unit">
                  <div class="content_num">
                      {{item.accidentPreventionCost}}
                  </div>
                </div>
                  <div class="content_desc">
                    事故预防费用(￥/元)
                  </div>
            </div>
          </div>
        </div>
      </div>
      <van-calendar v-model="show" :allow-same-day="true" type="range" @confirm="onConfirm" />
    </div>
</template>
<script>
import {getNdbg} from '../../api/api'
export default {
  name: "MyIndex",
  data () {
    return {
      show:false,
      date: '',
      dataList:[
    ],
      year: 2021,
      option1: [
        { text: '2021年', value: 2021 },
        { text: '2020年', value: 2020 },
        { text: '2019年', value: 2019 },
      ]

    };
  },
  watch:{
    year(){
      this.initData()
    }
  },
  mounted(){
    this.initData();
  },
  methods:{
    async initData(){
      let res = await getNdbg(this.year);
      this.dataList = res.data.data;
      console.log(res);
    },
    bqws (d) {
        if (d < 10) {
            return '0' + d
        } else {
            return d
        }
    },
    formmterTime(time){
        var date = new Date(time)
        var a = date.getFullYear()
        var b = date.getMonth() + 1
        var c = date.getDate()
        // var d = date.getDay()
        var e = a + '-' + this.bqws(b) + '-' + this.bqws(c)
        return e;
    },
    dateClick(){
      // console.log('123')
      this.show = true
    },
    formatDate(date) {
      return `${date.getMonth() + 1}/${date.getDate()}`;
    },
    onConfirm(date) {
      console.log(date)
      const [start, end] = date;
      this.show = false;
      this.date = [this.formmterTime(start),this.formmterTime(end)];
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .van-dropdown-menu__bar{
  background: none;
  box-shadow: none;
  height: auto;
  .van-dropdown-menu__item{
    flex: none;
    padding-left: 10px;
    height: 30px;
  }
}
.fxgk-container{
  display: flex;
  flex-direction: column;
  .fxgk_list{
    flex: 1;
    overflow-y: auto;
    font-size: 15px;
    margin: 10px;
    .fxgk_one{
      display: flex;
      flex-direction: column;
      background: #FFFFFF;
      box-shadow: 0px 0px 4px 0px rgba(205, 205, 205, 0.5);
      border-radius: 2px;
      padding: 10px;
      margin-bottom: 10px;
        .fxgk_one_title{
          // height: 24px;
          font-size: 16px;
          font-weight: 500;
          color: #494C5B;
          line-height: 24px;
          padding-left: 5px;
          display: flex;
          align-items: center;
          .title{
            width: 80%;
          }
          .type{
            height: 15px;
            font-size: 10px;
            font-weight: 400;
            color: #FFFFFF;
            line-height: 15px;
            padding: 2px;
            margin-left: 5px;
          }
        }
      .fxgk_one_content{
        // padding: 5px;
        .fxgk_content_one{
          display: flex;
          flex-direction: column;
          float: left;
          width: 50%;
          padding: 10px 5px;
          box-sizing: border-box;
          .content_num_unit{
            display: flex;
            color: #2195F2;
            align-items: center;
            .content_num{
              font-size: 18px;
            }
            .content_unit{
              font-size: 10px;
            }
          }
          .content_desc{
            font-size: 12px;
          }
        }
      }
    }
  }
}
</style>